var Promise = require('bluebird');
var error = require(_ROOT + '/app/errorLogger');
var dataRequest = require(_ROOT + '/app/data/dataRequest');

function create(values) {
  var def = Promise.defer();
  dataRequest.create('Feature', values).then(function(res) {
  	def.resolve(res);
  }).catch(Error, function(e) {
  	error.log(e);
  	def.reject(e);
  });
  return def.promise;
}

function read(id) {
  var def = Promise.defer();
  dataRequest.create('Feature', id).then(function(res) {
  	def.resolve(res);
  }).catch(Error, function(e) {
  	error.log(e);
  	def.reject(e);
  });
  return def.promise;
}

function del(id) {
  var def = Promise.defer();
  dataRequest.create('Feature', id).then(function(res) {
  	def.resolve(res);
  }).catch(Error, function(e) {
  	error.log(e);
  	def.reject(e);
  });
  return def.promise;
}

function update(id, values) {
  var def = Promise.defer();
  dataRequest.create('Feature', id, values).then(function(res) {
  	def.resolve(res);
  }).catch(Error, function(e) {
  	error.log(e);
  	def.reject(e);
  });
  return def.promise;
}

module.exports = {
  create: create,
  read: read,
  delete: del,
  update: update
};
